/**
 * Copyright (c) 2011-2017, Johnny Huang(huangzhiyi@gmail.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package heis.jfinal;

/**
 * Use this as Jetty server main
 * <pre>
 * args[0] --> webAppDir default --> "src/main/webapp"
 * args[1] --> port  default --> 80
 * args[2] --> context default --> "/"
 * args[3] --> scanIntervalSeconds  default -->5
 * </pre>
 * @author Johnny Huang
 *
 */
public class ServerMain {

	public static void main(String[] args){
		HJettyServer server=null;
		if (args == null || args.length == 0) {
			server = new HJettyServer("src/main/webapp",80, "/",5);
			server.start();
			return ;
		}
		
		// for Eclipse
		if (args.length == 4) {
			String webAppDir = args[0];
			int port = Integer.parseInt(args[1]);
			String context = args[2];
			int scanIntervalSeconds = Integer.parseInt(args[3]);
			server = new HJettyServer(webAppDir, port, context, scanIntervalSeconds);
			server.start();
			return ;
		}
		
		// for IDEA
		if (args.length == 3) {
			new HJettyServer(args[0], Integer.parseInt(args[1]),args[2],5).start();
			return ;
		}
		
		throw new RuntimeException("Boot parameter error. The right parameter like this: src/main/webapp 80 / 5");
	}
}
